package customview.ike.com.customviewproject.widget;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Build;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * Created by Administrator on 2017/12/9.
 */

public class BubbleTextView extends android.support.v7.widget.AppCompatTextView {
    BubbleDrawable drawable;
       
    public BubbleTextView(Context context) {
        this(context,null);
    }

    public BubbleTextView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public BubbleTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
     //   setPadding(getPaddingLeft(),getPaddingTop()+30,getPaddingRight(),getPaddingBottom());
    }

   
   
    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        if (w > 0 && h > 0) {
            setUp(w, h);
        }
    }

    private void setUp(int w, int h) {
        RectF rectF=new RectF(getPaddingLeft(),getPaddingTop(),w-getPaddingRight(),h-getPaddingBottom());
        drawable=new BubbleDrawable(rectF);
       setBackgroundDrawable(drawable);
    }

   

    @Override
    public void layout(int l, int t, int r, int b) {
        super.layout(l, t, r, b);
        setUp(getWidth(),getHeight());
    }
}
